package com.mk.Service.Impl;

import com.mk.Entity.Blog;
import com.mk.Entity.queryObject;
import com.mk.Mapper.BlogMapper;
import com.mk.Service.IBlogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class BlogServiceImpl implements IBlogService {

    @Autowired
    BlogMapper blogMapper;
    @Override
    public List<Blog> queryAll(queryObject queryObject) {
        List<Blog> blist=blogMapper.selectAll(queryObject);
        return blist;
    }

    @Override
    public List<Blog> queryByTagId(queryObject queryObject) {
        List<Blog> blist=blogMapper.selectByTagId(queryObject);
        return blist;
    }

    @Override
    public List<List<Blog>> queryBlogByTime(List<String> strings) {
        List<List<Blog>> blogsList=new ArrayList<>();
        if (strings!=null){
            for (String updateTime:
                 strings) {
                List<Blog> blogs = blogMapper.selectBlogByTime(updateTime);
                blogsList.add(blogs);
            }

            return blogsList;
        }
        return null;
    }

    @Override
    public List<String> queryAllTime(queryObject queryObject) {
        List<String> strings = blogMapper.selectAllTime(queryObject);
        return strings;
    }

    @Override
    public List<String> queryTime() {
        return blogMapper.selectTime();
    }

    @Override
    public Blog queryOne(Long bid) {
       Blog blog= blogMapper.selectOne(bid);
       return blog;
    }


    @Override
    public Integer queryCount(queryObject queryObject) {
        return blogMapper.selectCount(queryObject);
    }


    @Override
    public void deleteBlog(Long did) {
        blogMapper.deleteBlog(did);
    }

    @Override
    public void insertBlog(Blog blog) {
        blogMapper.insert(blog);
    }

    @Override
    public void updateBlog(Blog blog) {
        blogMapper.update(blog);
    }
}
